package net.NingXiaRuiTai.ShortChain.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import lombok.extern.slf4j.Slf4j;
import net.NingXiaRuiTai.ShortChain.Manager.DomainManager;
import net.NingXiaRuiTai.ShortChain.interceptor.LoginInterceptor;
import net.NingXiaRuiTai.ShortChain.model.DomainDO;
import net.NingXiaRuiTai.ShortChain.model.VO.DomainVO;
import net.NingXiaRuiTai.ShortChain.service.DomainService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service
@Slf4j
public class DomainServiceImpl implements DomainService {
    @Resource
    private DomainManager domainManager;
    @Override
    public boolean saveBatch(Collection<DomainDO> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdateBatch(Collection<DomainDO> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean updateBatchById(Collection<DomainDO> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdate(DomainDO entity) {
        return false;
    }

    @Override
    public DomainDO getOne(Wrapper<DomainDO> queryWrapper, boolean throwEx) {
        return null;
    }

    @Override
    public Map<String, Object> getMap(Wrapper<DomainDO> queryWrapper) {
        return null;
    }

    @Override
    public <V> V getObj(Wrapper<DomainDO> queryWrapper, Function<? super Object, V> mapper) {
        return null;
    }

    @Override
    public BaseMapper<DomainDO> getBaseMapper() {
        return null;
    }

    @Override
    public Class<DomainDO> getEntityClass() {
        return null;
    }

    @Override
    public List<DomainVO> listAll() {
        long accountNo = LoginInterceptor.threadLocal.get().getAccountNo();
        List<DomainDO> customDomainList=domainManager.listCustomDomain(accountNo);
        List<DomainDO> listOfficialDomain=domainManager.listOfficialDomain();
        customDomainList.addAll(listOfficialDomain);

        return customDomainList.stream().map(obj->beanProcess(obj)).collect(Collectors.toList());
    }
    private  DomainVO beanProcess(DomainDO domainDO){
        DomainVO domainVO=new DomainVO();
        BeanUtils.copyProperties(domainDO,domainVO);
        return domainVO;
    }
}
